<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreCarouselRequest;
use App\Http\Requests\UpdateCarouselRequest;
use App\Models\Carousel;

class CarouselController extends Controller
{
    public function index()
    {
        return Carousel::all();
    }


    public function store(StoreCarouselRequest $request)
    {
        $request->validate([
            'title' => ['required'],
            'image' => ['required'],
        ]);
        Carousel::create($request->input());
        return $this->message('添加成功');
    }

    public function show(Carousel $carousel)
    {
        return $carousel;
    }


    public function update(UpdateCarouselRequest $request, Carousel $carousel)
    {
        $request->validate([
            'title' => ['required'],
            'image' => ['required'],
        ]);
        $carousel->update($request->input());
        return $this->message('修改成功');
    }


    public function destroy(Carousel $carousel)
    {
        $carousel->delete();
        return $this->message("删除成功");
    }
}
